/**
 *	Yggdrasil World Framework Toolkit
 *	(A component of the NeuroCoSA toolkit)
 *	Copyright (C) 2001-5 Stuart Meikle.
 *
 *	This is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 * @author	Stuart Meikle
 * @version	20050812
 * @license	LGPL
 */

package org.stumeikle.Yggdrasil;


/** Simple class for World - Yggdrasil communications. 
 *  Used by Ygg to signal World that a new elf is ready for existence.
 *  Written 20010403 by StuMeikle.
 */
public class	FountainOfLife
{
    public	Life		creature_life;	//pointer for the body now...
    public	String		newcreaturetype;/**readonly for world */
    public	int		creature_count;
    public	int		acknowledge;	/**mutex	, wo for world */

    FountainOfLife()
    {
	acknowledge = 0;
	newcreaturetype=null;
	creature_count  =0;
	creature_life   =null;
    }

    synchronized String getNewCreatureType()
    {
	return newcreaturetype;
    }

    private synchronized int getAcknowledge()
    {
	return acknowledge;
    }

    synchronized void setNewCreatureType(String v)
    {
	newcreaturetype = v;
    }

    private synchronized void setAcknowledge(int v)
    {
	acknowledge = v;
    }

    private synchronized int getCreatureCount()
    { return creature_count; }

    private synchronized void setCreatureCount(int v)
    { creature_count=v; }


    public boolean newCreature()
    {
	if (getCreatureCount()>getAcknowledge())
	    return true;
	else
	    return false;
    }

    public void acknowledge()
    {
	setAcknowledge( getCreatureCount() );
    }

    public void setNewCreaturePresent()
    {
	while (getCreatureCount()>getAcknowledge());	//block until ack==newelf
	setCreatureCount( getCreatureCount()+1 );
    }
   
    
    public void	setLife( Life l )
    { creature_life = l; }
    
    public Life getLife() 
    { return creature_life; }
}

